package com.hxy.health.platform.controller;

import com.github.pagehelper.PageInfo;
import com.hxy.health.platform.pojo.Gallery;
import com.hxy.health.platform.service.GalleryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class GalleryController {
    @Autowired
    private GalleryService galleryService;

    /**
     * 跳转到服务界面
     */
    @RequestMapping("page/gallery")
    public String servicePage(ModelMap modelMap) {
        List<Gallery> galleries = galleryService.getAll();
        modelMap.addAttribute("galleries", galleries);
        return "gallery";
    }

    /**
     * 跳转到服务详情界面
     */
    @RequestMapping("page/galleryDetail")
    public String serviceDetailPAge(@RequestParam("id") Integer id, ModelMap modelMap) {
        Gallery gallery = galleryService.getById(id);
        modelMap.addAttribute("gallery", gallery);
        return "galleryDetail";
    }

    /**
     * 搜索服务
     */
    @RequestMapping("gallery/searchGallery")
    public String searchGallery(@RequestParam("question") String question, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, ModelMap modelMap) {
        PageInfo<Gallery> pageInfo = galleryService.search(pageNum, pageSize, question);
        modelMap.addAttribute("galleries", pageInfo.getList());
        return "gallery";

    }


}
